package javagame;

import gameobjects.Igrac;
import gameobjects.Igrac2;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import java.awt.Font;

public class GameOver2 extends BasicGameState {
	
	private Image slika;
	private int slikaX = 0;
	private int slikaY = 0;
	private Igrac tenkIgrac;
	private Igrac2 tenkIgrac2;
	private Font font;
	private TrueTypeFont ttf;
	
	public GameOver2 (int state) {
		
	}

	public int getID() {
		return 19;
	}

	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		slika = new Image("res/game_over2.png");
		tenkIgrac = Igrac.dohvIgraca();
		tenkIgrac2 = Igrac2.dohvIgraca();
		font = new Font("Courier New", Font.BOLD, 40);
		ttf = new TrueTypeFont(font, false);
	}

	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.drawImage(slika, slikaX, slikaY);
		
		float pomeraj = ttf.getWidth("Player 1 score: " + tenkIgrac.getBodovi()) - ttf.getWidth("Player 1 score: 0");
		ttf.drawString(315-pomeraj/2, 305, "Player 1 score: " + tenkIgrac.getBodovi());
		if (Nivo.isDvaIgraca()) {
			pomeraj = ttf.getWidth("Player 2 score: " + tenkIgrac2.getBodovi()) - ttf.getWidth("Player 2 score: 0");
			ttf.drawString(315-pomeraj/2, 345, "Player 2 score: " + tenkIgrac2.getBodovi());
		}
	}

	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input input = gc.getInput();
				
		int xpos = Mouse.getX();
		int ypos = Mouse.getY();
		
		//continue
		if ((xpos>420 && xpos<1165) && (ypos>190 && ypos<290)) {
			if (input.isMousePressed(0)) {
				tenkIgrac.ozivi();
				if (Nivo.isDvaIgraca())
					tenkIgrac2.ozivi();
				sbg.enterState(Nivo.getNivo());
			}
		}
		//exit
		if ((xpos>420 && xpos<1165) && (ypos>80 && ypos<180)) {
			if (input.isMousePressed(0)) {
				tenkIgrac.ozivi();
				if (Nivo.isDvaIgraca())
					tenkIgrac2.ozivi();
				Nivo.setNivo(5);
				sbg.enterState(0);
			}
		}
	}

}
